package cn.canxin.common.web.tools;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import org.jeewx.api.core.exception.WexinReqException;
import org.json.JSONObject;

import java.util.Random;

/**
 * Created by Administrator on 2017/5/10.
 */
public class NetworkTools {

    public static void sendMessageAuthCode(String mobileNo,String code) throws ApiException {
        String url = "http://gw.api.taobao.com/router/rest";
        String appKey = "23812084";
        String secret = "ab66f09b63dc40f7b9f8ef3cf8f1dcfe";
        TaobaoClient client = new DefaultTaobaoClient(url, appKey, secret);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setExtend("123456");
        req.setSmsType("normal");
        req.setSmsFreeSignName("灿欣科技");
        JSONObject params = new JSONObject();
        params.put("code",code);
        req.setSmsParamString(params.toString());
        req.setRecNum(mobileNo);
        req.setSmsTemplateCode("SMS_66630050");
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        System.out.println(rsp.getBody());
    }

    public static  String generateRandomNumber()
    {
        int num = (int)((Math.random()*9+1)*100000);
        return String.valueOf(num);
    }

    public static  String getWxAccessToken() throws WexinReqException {
        String appId = "wx392d4299ad1a4826";
        String appsecret  ="8cdc91ba124b48eaa8b5f052f52acd8b";
        String token = org.jeewx.api.wxbase.wxtoken.JwTokenAPI.getAccessToken(appId,appsecret);
        return token;
    }

    public static void main(String[] args) throws WexinReqException {
        System.out.println(getWxAccessToken());
    }
}
